﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Practices.Unity;
using Microsoft.Practices.Composite.Regions;
using Microsoft.Practices.Composite.Events;
using VpPrism.Modules.ModuleTwo.Views;
using VpPrism.Modules.ModuleTwo.ViewModels;
using VpPrism.Modules.ModuleTwo.Controllers;

namespace VpPrism.Modules.ModuleTwo.Module
{
  /// <summary>
  /// Classe Module pour ModuleTwo (implémentant Microsoft.Practices.Composite.Modularity.IModule)
  /// </summary>
  public class ModuleTwoModule : Microsoft.Practices.Composite.Modularity.IModule
  {
    private readonly IUnityContainer _container;
    private readonly IRegionManager _regionManager;

    /// <summary>
    /// Constructeur. Avec passage du UnityContainer.
    /// </summary>
    /// <param name="unityContainer"></param>
    public ModuleTwoModule(IUnityContainer unityContainer)
    {
      _container = unityContainer;
      _regionManager = _container.Resolve<IRegionManager>();
    }

    /// <summary>
    /// Fonction d'initialisation: Appelée sur le Load du Module
    /// </summary>
    public void Initialize()
    {
      this.RegisterViewsAndServices();

      var controller = this._container.Resolve<IModuleTwoMainController>();
      controller.Run();
    }

    /// <summary>
    /// Fonction regroupant les enregistrements dans le container.
    /// </summary>
    protected void RegisterViewsAndServices()
    {
      // Exemple de register en singleton :
      //_container.RegisterType<IModuleTwoService, ModuleTwoService>(new ContainerControlledLifetimeManager());

      _container.RegisterType<IModuleTwoMainV, ModuleTwoMainV>();
      _container.RegisterType<IModuleTwoMainVM, ModuleTwoMainVM>();
      _container.RegisterType<IModuleTwoMainController, ModuleTwoMainController>();
    }
  }
}
